<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title th:text="${systemInfo.sitename}+'-书源添加'">逗逼阅读 - 书源添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="逗逼联盟,逗逼阅读,无广告,小说" th:content="${systemInfo.metaKeywords}" />
    <meta name="description" content="做最简洁，最干净的小说聚合网站" th:content="${systemInfo.metaDescription}" />
    <link rel="stylesheet" th:href="@{/lib/layuimini/lib/layui-v2.5.4/css/layui.css}"
          href="../../../../static/lib/layuimini/lib/layui-v2.5.4/css/layui.css" media="all">
    <link rel="stylesheet" th:href="@{/lib/layuimini/css/public.css}"
          href="../../../../static/lib/layuimini/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" method="post" action="doAdd">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>基础信息</legend>
            </fieldset>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>书源名称:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="name" required lay-verify="required" lay-reqtext="名称不能为空"
                           placeholder="请输入名称"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>书源地址:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="baseUrl" lay-verify="required|url" lay-reqtext="地址不能为空"
                           placeholder="请输入地址"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <input type="hidden" name="imageError" value="$(this).attr('src', '/imgs/nocover.jpg')">

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>书籍搜索设置</legend>
            </fieldset>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>搜索地址:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="searchUrl" required lay-verify="required" lay-reqtext="搜索地址不能为空"
                           placeholder="请输入搜索地址"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>书籍搜索结果解析</legend>
            </fieldset>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>结果集列表:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="searchResultSelector" required lay-verify="required"
                           lay-reqtext="搜索结果集列表不能为空" placeholder="请输入搜索结果集列表筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>书籍名称:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="resultItemBookNameSelector" required lay-verify="required"
                           lay-reqtext="搜索结果书籍名称不能为空" placeholder="请输入搜索结果书籍名称筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>书籍地址:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="resultItemBookUrlSelector" required lay-verify="required"
                           lay-reqtext="搜索结果书籍地址不能为空" placeholder="请输入搜索结果书籍地址筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    封面地址:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="resultItemBookImageUrlSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    书籍描述:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="resultItemBookDesSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    书籍作者:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="resultItemBookAuthorSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    书籍类型:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="resultItemBookTypeSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    更新时间:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="resultItemBookLastUpdateSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    最新章节名:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="resultItemBookLastNewSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="data-test0-btn">测试搜索解析</button>
                </div>
            </div>

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>书籍详情解析</legend>
            </fieldset>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>名称:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookDetailBookNameSelector" required lay-verify="required"
                           lay-reqtext="书籍详情-名称不能为空" placeholder="请输入书籍详情-名称筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    作者:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookDetailBookAuthorSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    更新时间:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookDetailBookLastUpdateSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    最新章节名:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookDetailBookLastNewSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    描述:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookDetailBookDesSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    封面:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookDetailBookImageUrlSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>章节列表:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookDetailCatalogListSelector" required lay-verify="required"
                           lay-reqtext="书籍详情-章节列表不能为空" placeholder="请输入书籍详情-章节列表筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>章节名称:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookDetailCatalogItemNameSelector" required lay-verify="required"
                           lay-reqtext="书籍详情-章节名称不能为空" placeholder="请输入书籍详情-章节名称筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>章节链接:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookDetailCatalogItemLinkSelector" required lay-verify="required"
                           lay-reqtext="书籍详情-章节链接不能为空" placeholder="请输入书籍详情-章节链接筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="data-test1-btn">测试章节列表解析</button>
                </div>
            </div>

            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>章节内容解析</legend>
            </fieldset>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    书籍名称:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookContentNameSelector" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>章节名称:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookContentCatalogNameSelector" required lay-verify="required"
                           lay-reqtext="章节详情-章节名称不能为空" placeholder="请输入章节详情-章节名称筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>章节内容:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookContentSelector" required lay-verify="required"
                           lay-reqtext="章节详情-章节内容不能为空" placeholder="请输入章节详情-章节内容筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    内容过滤正则:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="contentRegex" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    广告文字过滤:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookContentAds" autocomplete="off" class="layui-input" placeholder="多组用‘##’间隔，例如：广告1##广告2">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>上一章:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookContentPreCatalogSelector" required lay-verify="required"
                           lay-reqtext="章节详情-上一章不能为空" placeholder="请输入章节详情-上一章筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>章节列表:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookContentCatalogListSelector" required lay-verify="required"
                           lay-reqtext="章节详情-章节列表不能为空" placeholder="请输入章节详情-章节列表筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="we-red">*</span>下一章:
                </label>
                <div class="layui-input-block">
                    <input type="text" name="bookContentNextCatalogSelector" required lay-verify="required"
                           lay-reqtext="章节详情-下一章不能为空" placeholder="请输入章节详情-下一章筛选条件"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="data-test2-btn">测试章节内容解析</button>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="data-add-btn">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script th:src="@{/lib/layuimini/lib/layui-v2.5.4/layui.js(v=1.0.4)}"
        src="../../../../static/lib/layuimini/lib/layui-v2.5.4/layui.js?v=1.0.4" charset="utf-8"></script>
<script th:src="@{/js/admin.js}" src="../../../../static/js/admin.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form;

        //监听测试0提交操作
        form.on('submit(data-test0-btn)', function (data) {
            layer.prompt({
                title:'请输入搜索书籍名称',
                formType:2,
            },function (text,index) {
                layer.close(index);
                index = layer.load();
                data.field.key = text;
                data.field.type=0;
                $.ajax({
                    url: 'doTest',
                    method: 'post',
                    data: data.field,
                    dataType: 'json',
                    success: function (result) {
                        var message = result.message;
                        if (result.success) {
                            layer.close(index);
                            parent.layer.alert(JSON.stringify(result.values));
                            return;
                        }
                        layer.close(index);
                        parent.layer.alert(message);
                    },
                    error: function () {
                        layer.close(index);
                        layer.msg('测试失败:网络异常，请稍后再试');
                    }
                });
            });
            return false;
        });

        //监听测试1提交操作
        form.on('submit(data-test1-btn)', function (data) {
            layer.prompt({
                title:'请输入书籍章节地址',
                formType:2,
            },function (text,index) {
                layer.close(index);
                index = layer.load();
                data.field.key = text;
                data.field.type=1;
                $.ajax({
                    url: 'doTest',
                    method: 'post',
                    data: data.field,
                    dataType: 'json',
                    success: function (result) {
                        var message = result.message;
                        if (result.success) {
                            layer.close(index);
                            parent.layer.alert(JSON.stringify(result.values));
                            return;
                        }
                        layer.close(index);
                        parent.layer.alert(message);
                    },
                    error: function () {
                        layer.close(index);
                        layer.msg('测试失败:网络异常，请稍后再试');
                    }
                });
            });
            return false;
        });

        //监听测试2提交操作
        form.on('submit(data-test2-btn)', function (data) {
            layer.prompt({
                title:'请输入书籍阅读界面地址',
                formType:2,
            },function (text,index) {
                layer.close(index);
                index = layer.load();
                data.field.key = text;
                data.field.type=2;
                $.ajax({
                    url: 'doTest',
                    method: 'post',
                    data: data.field,
                    dataType: 'json',
                    success: function (result) {
                        var message = result.message;
                        if (result.success) {
                            layer.close(index);
                            result.values.content = result.values.content.substring(0,100)+'......(屏蔽后续过多内容)';
                            parent.layer.alert(JSON.stringify(result.values));
                            return;
                        }
                        layer.close(index);
                        parent.layer.alert(message);
                    },
                    error: function () {
                        layer.close(index);
                        layer.msg('测试失败:网络异常，请稍后再试');
                    }
                });
            });
            return false;
        });

        // 监听提交操作
        form.on('submit(data-add-btn)', function (data) {
            var index = layer.load();
            $.ajax({
                url: 'doAdd',
                method: 'post',
                data: data.field,
                dataType: 'json',
                success: function (result) {
                    var message = result.message;
                    if (result.success) {
                        if (message == null || message == '' || message == undefined) {
                            message = '添加成功';
                        }
                        layer.close(index);

                        index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.reloadTable();
                        return;
                    }
                    if (message == null || message == '' || message == undefined) {
                        message = '添加失败:未知错误';
                    }
                    layer.close(index);
                    layer.msg(message);
                },
                error: function () {
                    layer.close(index);
                    layer.msg('添加失败:网络异常，请稍后再试');
                }
            });
            return false;
        });
    });

</script>

</body>
</html>